package com.my.controller;


import com.alibaba.fastjson.JSONObject;
import com.my.bean.*;
import com.my.service.InventoryService;
import com.my.service.LossService;
import com.my.service.StockService;
import com.my.util.SessionUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.sql.SQLException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 库存盘点 前端控制器
 * @author 张子艺
 * @since 2018-08-26
 */
@Controller
@RequestMapping("/inventory")
public class InventoryController {

    @Autowired
    InventoryService inventoryService;

    //跳转
    @RequestMapping("main.html")
    public String main() {
        return  "Inventory";
    }
    //跳转
    @RequestMapping("inventoryAdd.html")
    public String inventoryAdd() {
        return  "/Alert/inventory_add";
    }


    //新增
    @RequestMapping("insertInventory")
    @ResponseBody

    public String insertInventory(String param,HttpSession session)  {
        try {
            Long areaid =((User)session.getAttribute("user")).getAreaId();
            return  inventoryService.insertInventory(param,areaid);
        } catch (SQLException e) {
            return  "失败，服务器错误";
        }
    }
    //查询
    @RequestMapping("list")
    @ResponseBody
    public ResultPage<Inventory> list(VoPage voPage, Inventory inventory, HttpSession session) {
        boolean admin=false;
        //如果事超级管理员  即可查看所有的房间  判断是否为超级管理员
        if(SessionUtil.getSessionUser(session).getRoles().getRoleValue().equals("9f77d5a8-75c6-4d06-adf9-a37e727d491a")){
            admin=true;
        }
        Long areaid = ((User)session.getAttribute("user")).getAreaId();
        return  inventoryService.selectMyPage(inventory,voPage,areaid,admin);
    }
}